// Time:  O(m + n)
// Space: O(1)

#include <vector> 

using namespace std;

class Solution {
public:
    vector<vector<int>> intervalIntersection(vector<vector<int>>& firstList, vector<vector<int>>& secondList) {
        vector<vector<int>> result;
        int i = 0, j = 0;
        while (i < firstList.size() && j < secondList.size()) {
            int left = max(firstList[i][0], secondList[j][0]);    // Access first element
            int right = min(firstList[i][1], secondList[j][1]);   // Access second element
            
            if (left <= right) {
                result.push_back({left, right});  // Use vector initialization
            }
            
            if (firstList[i][1] < secondList[j][1]) {
                ++i;
            } else {
                ++j;
            }
        }
        return result;
    }
};
